package com.todaynews;

import androidx.appcompat.app.AppCompatActivity;

import android.Manifest;
import android.annotation.SuppressLint;
import android.os.Bundle;
import com.tbruyelle.rxpermissions2.RxPermissions;
import com.todaynews.frame.image.tool.ui.ToastUtil;
import com.todaynews.utils.file.FileUtils;

public class MainActivity extends AppCompatActivity {

    private RxPermissions rxPermissions;

    @SuppressLint("CheckResult")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        rxPermissions = new RxPermissions(this);
        rxPermissions
                .request(Manifest.permission.READ_EXTERNAL_STORAGE,
                        Manifest.permission.WRITE_EXTERNAL_STORAGE)
                .subscribe(granted -> {
                    if (granted) {
                        // All requested permissions are granted
                        if(FileUtils.getInstance().createCacheRootDirectory()){
                            ToastUtil.getInstance()._short(this,"成功");
                        }else {
                            ToastUtil.getInstance()._short(this,"失败");
                        }
                    } else {
                        // At least one permission is denied
                        ToastUtil.getInstance()._short(this,"权限申请失败");
                    }
                });
    }
}
